package com.micromall.task;

import com.micromall.repository.OrderMapper;
import com.micromall.service.TransactionalExecuteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 订单超时未支付自动关闭任务
 *
 * @author zhangzxiang91@gmail.com
 * @date 2016/04/09.
 */
@Component
public class OrderTimeoutCloseTask {

	private static Logger logger = LoggerFactory.getLogger(OrderTimeoutCloseTask.class);
	@Resource
	private OrderMapper                 orderMapper;
	@Resource
	private TransactionalExecuteService transactionalExecuteService;

	@Scheduled(cron = "0 0/1 * * * ?")
	public void execute() {
		transactionalExecuteService.execute(() -> logger.info("关闭超时未支付订单 {} 条", orderMapper.closeTimeoutNotPayOrders(new Date())));

	}
}
